package com.example.train.api.controller.v1;

import com.example.train.api.dto.DepartmentDTO;
import com.example.train.app.service.DepartmentService;
import com.example.train.domain.entity.Department;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: ActingK20 42643
 * @Date: 2023/3/25 13:52
 */
@RestController
@RequestMapping("/dep")
public class DepartmentController {
    private final DepartmentService departmentService;

    public DepartmentController(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    @GetMapping("/list")
    public ResponseEntity<?> list(Long id) {
        List<Department> departments = departmentService.ListDepartments(id);
        return ResponseEntity.ok(departments);
    }

    @PostMapping("/insert")
    public  ResponseEntity<?> intDepartment(@RequestBody DepartmentDTO departmentDTO){
        Integer integer = departmentService.IntDepartments(departmentDTO);
        return ResponseEntity.ok(integer);
    }

    @PostMapping("/update")
    public ResponseEntity<?> updateDepartment(@RequestBody DepartmentDTO departmentDTO){
        Integer integer = departmentService.updateDepartments(departmentDTO);
        return ResponseEntity.ok(integer);
    }
    @PostMapping("/del")
    public ResponseEntity<?> delDepartment(@RequestParam("id") Long id){
        Integer integer = departmentService.delDepartment(id);
        return ResponseEntity.ok(integer);
    }
}